<template>
	
 	<div class="layui-layout layui-layout-admin" >
 	  <div class="adminnav1">	
        <Pagetop></Pagetop>
      </div>
      <div class="adminnav2">	
       	<Secondnav urlname="order"></Secondnav>
      </div>
      
      <!-- 主体内容 -->
      <div class="layui-body kedou-admin" id="LAY_app_body app">
	    <div class="layadmin-tabsbody-item layui-show">
	    	<div class="pagelist">
	    		<div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
					  <legend>(WUC)商城订单管理</legend>
					</fieldset>
		      	</div>
	    		<div class="pagetop">
	    			<Search :seadate="searchArr"></Search>			    	
		        </div>
		        <div class="layui-card-body">
		        	<div class="buttop" id="buttop">
					    <button type="button" class="layui-btn" @click="getData(0)">全部</button>
					    <button type="button" class="layui-btn  layui-btn-primary" @click="getData(1)">待发货订单</button>
					    <button type="button" class="layui-btn  layui-btn-primary" @click="getData(2)">退款审核订单</button>
					    <button type="button" class="layui-btn  layui-btn-primary" @click="getData(3)">已完成订单</button>					    					 
		        	</div>
			        <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex" :fbtn="btn"></Tables>      			     
		        </div>		      
	        </div>
	    </div>
	  </div>  
	     
	</div>
</template>
<script>	
	import Pagetop from '../../common/pagetop.vue'
	import Secondnav from '../../common/secondnav.vue'
	import Tables from '../../common/tables.vue'
	import Search from '../../common/search.vue'
	export default {
	  name: 'wucorder',
	  components: {Pagetop,Secondnav,Tables,Search},	  
	  data () {
	    return {
	        pdate:[], //表头  	
	    	res:"", //内容
	    	totalRows:"",//总数量
	    	curindex:1, //页数
	    	btn:[],//按钮
	    	searchArr:[],//搜索
	    	isShow:false, 
	    	seapram:'',
	    	isclick:0,	    	
	    }
	  },
	  mounted(){ 	
	  	this.getdate();
     	this.getsearch();
	  },
	  methods: {	 	  
		getdate:function(){     	
    	var _this=this;
    	if(_this.isclick==0){
    		var condition=''; //全部   		
    	}else if(_this.isclick==1){
    		var condition='PAID'; //待发货    	
    	}else if(_this.isclick==2){
    		var condition='APPLY_REFUND';//退款审核
    	}else if(_this.isclick==3){
    		var condition='COMPLETED';	//已完成
    	}
    	var url="/order/bapi/v1.9/order"    	
    	if(_this.seapram){
    		var dates={
	    		 size:pageSize,
	    		 page:_this.curindex,
	    		 'status.equals':condition,
		         sort:'createAt,DESC',
				 //'status.equals':'ENABLE'
				 'orderTypeId.equals':6
	    	}
    		var res=_this.seapram;
    		for(var i=0;i<res.length;i++){
    			//dates[res[i].key]=res[i].val;
    			dates[res[i].key+'.contains']=res[i].val;
    		}
    		
    	}else{
	    	var dates={
	    		 size:pageSize,
	    		 page:_this.curindex,
	    		 'status.equals':condition,
				 sort:'createAt,DESC',
				 'orderTypeId.equals':6
	    	}
        }  		    	
        //	alert(url+"//"+JSON.stringify(dates))
      	ajaxRequest(url,'GET','json',dates,function(ret,err){
      		//alert(url+"//"+JSON.stringify(ret))
	  		var arr=[];  		
		  	arr[0]=[ 
		       {field: 'serialNo', title: '订单号'}
		      ,{field: 'createAt', title: '创建时间',templet:function(d){return FormatDate(d.createAt)}}
		      ,{field: 'orderItemVMS', title: '商品图片',templet:'<div><img src="{{d.orderItemVMS[0].itemPicture}}" style="display: inline-block; height: 100%;"></div>'}	
		       ,{field: 'orderItemVMS', title: '商品名称',templet:function(d){
			        if(d.orderItemVMS!=null){
			      		for(var i=0;i<d.orderItemVMS.length;i++){
			      			return d.orderItemVMS[i].itemName
			      		}
			      	}		  
			       }}
		       ,{field: 'orderItemVMS', title: '数量',templet:function(d){
		        if(d.orderItemVMS!=null){
		      		for(var i=0;i<d.orderItemVMS.length;i++){
		      			return d.orderItemVMS[i].amount
		      		}
		      	}		  
		       }}	
		       ,{field: 'orderItemVMS', title: '单价',templet:function(d){
		        if(d.orderItemVMS!=null){
		      		for(var i=0;i<d.orderItemVMS.length;i++){
		      			return d.orderItemVMS[i].price/100
		      		}
		      	}		  
		       }}
		      ,{field: 'totalAmount', title: '合计（元）',templet:function(d){return d.totalAmount/100}} 
			  ,{field: 'postage', title: '邮费（元）',templet:function(d){return d.postage/100}}
			  ,{field: 'payAmount', title: '实付款（元）',templet:function(d){return d.payAmount/100}}
			  ,{field: 'payAmount', title: '抵扣情况',templet:function(d){
			  	if(d.deductionList&&d.deductionList.length>0){
			  		var arr=d.deductionList;
			  		var str=''
			  		for(var i=0;i<arr.length;i++){
			  			if(arr[i].payTypeId==13){
			  				str=str+'抵扣'+arr[i].amount/100+"WUC(积分),"
			  			}
			  			else if(arr[i].payTypeId==12){
			  				str=str+'抵扣'+arr[i].amount/100+"UC,"
			  			}
			  			
			  			else if(arr[i].payTypeId==211){
			  				str=str+'抵扣'+arr[i].amount/100+"共享金,"
			  			}
			  			else if(arr[i].payTypeId==212){
			  				str=str+'抵扣'+arr[i].amount/100+"消费金,"
			  			}
			  		}
			  		return str
			  	}
			  	else{
			  		return ''
			  	}
			  }}
			  ,{field: 'status', title: '状态',templet:function(d){
			  	if(d.status=='UNPAID')return '等待付款'
			    else if(d.status=='PAID')return '已付款'
			    else if(d.status=='GOODS_RECEIVED')return '等待收货'
			    else if(d.status=='COMPLETED')return '已完成'
			    else if(d.status=='WITHDRAW')return '等待取消审核'
			    else if(d.status=='CANCEL')return '已取消'
			    else if(d.status=='APPLY_REFUND')return '等待退款审核'
			    else if(d.status=='REFUND')return '已退款'
			    else return''
			  }}
			  ,{field: 'right',title: '操作', width:'150', fixed:'right',templet:function(d){ 
		         var str='<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">详情</a>';
		         if(d.status=="PAID"||d.status=="APPLY_REFUND"){
		         	if(d.status=="PAID"){
		         	    var str1='<a class="layui-btn layui-btn-xs " lay-event="edit">确认发货</a>';
		         	}else if(d.status=="APPLY_REFUND"){
		         		var str1='<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="upper">确认退款</a>';
		         	}else{
		         		var str1='';
		         	}
		         }else{
		         	var str1='';
		         }
		         return str+str1;
		      }}
		  	];
//		    var res1=[]
//		    res1=[{a:'1',b:'小m'},{a:'1',b:'小m'},]		    		   		  	
		  	_this.pdate=arr;		  	
		  	_this.res=ret.data.list; //res1; 		  
		  	_this.totalRows=ret.data.totalRows;
		  	_this.curindex=ret.data.page+1;		  	
	    })	
    },     
     getsearch:function(){
    	var arr=[
    		{field: 'serialNo', title: '订单号',type: 'input'}     	
    	];
    	this.searchArr=arr;
   	
    },
    page:function(index,obj){
    	//alert(JSON,stringify(obj))
    	this.curindex=index;
    	this.getdate();    	
    }, 
    sousuo:function(pram){
    	//alert(JSON.stringify(pram))
    	this.seapram=pram;
    	this.res='';
    	this.totalRows='';
    	this.curindex=1;
    	this.getdate();
    },   
    getData:function(is){
    	this.isclick=is;
    	this.getdate();
    	if(is==0){
    	  $('#buttop').find('.layui-btn:eq(0)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
    	}else if(is==1){
    	  $('#buttop').find('.layui-btn:eq(1)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')  
    	}else if(is==2){
    	  $('#buttop').find('.layui-btn:eq(2)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(3)').addClass('layui-btn-primary')
    	}else if(is==3){
    	  $('#buttop').find('.layui-btn:eq(3)').removeClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(0)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(1)').addClass('layui-btn-primary')
    	  $('#buttop').find('.layui-btn:eq(2)').addClass('layui-btn-primary')  
    	}       
	},
	addData:function(){     	
       // this.$router.push({name:'jfadd'})	
	},
	detailInfo:function(data){
		//this.$router.push({name:'jfadd',query:{'shopId':data.shopId,'commodityId':data.commodityId}})	
	    var _this = this;
		var datas={
			id:data.id,			
		}
		layer.open({
            type: 2
            ,title: '商城订单详情'
            ,shadeClose: false//点击遮罩关闭
            ,content:baseurl+'wucdetail'
            ,area: _this.screens() < 2 ? ['90%', '80%'] : ['650px', '550px']          
            ,success : function(layero, index){
		        var iframeWin = window[layero.find('iframe')[0]['name']];
		        iframeWin.getdates(datas);
	        },	      
        });
	},
	editInfo:function(data){//发货
		var _this = this;
		layer.confirm('是否确认发货？', function(){
			var url='/order/bapi/v1.9/order/deliverOrder?orderId='+data.id
			ajaxRequest(url,'PUT','json','',function(ret,err){			    
		      	layer.msg('操作成功');
		    	var is=_this.isclick;
		    	setTimeout(function(){
				  	 _this.getData(is)
		        },1000)	 
			})
		});	
	},
    upperInfo:function(data){//退款
    	var _this = this;
		layer.confirm('是否确认退款？', function(){
			var dates={				
				orderId:data.id								
			}
			var url='/order/bapi/v1.9/order/applyRefund';
			ajaxRequest(url,'POST','json',dates,function(ret,err){
			    layer.msg("操作成功");		      	
		    	var is=_this.isclick;
		    	setTimeout(function(){
				  	 _this.getData(is)
		        },1000)	 
			})
		});	
    },
	screens:function(){
		return screen();
	},	
  },
  updated:function(){
  	this.isShow = true;
	layui.use('form', function(){
	  var form = layui.form;
	  form.render();	 
	});
  },
}
</script>
<style scoped>
/**/
</style>
